<?PHP


	require_once __CFG_PATH_LIBS . __CFG_PATH_CORE . "general.php";
	checkDomainName();

	require_once __CFG_PATH_LIBS . "xx/class.Timer.php";
	$Timer = new Timer();

    $Timer->start("common");
	$Timer->start("loader");
	$GEOIP_COUNTRY_CODE = "";

	require_once __CFG_PATH_LIBS . "xx/class.Session.php";
	require_once __CFG_PATH_LIBS . "xx/class.Database.php";
	require_once __CFG_PATH_LIBS . "xx/class.XMLPage.php";
	require_once __CFG_PATH_LIBS . "xx/class.PageContent.php";
	require_once __CFG_PATH_LIBS . "xx/class.Statistic.php";
	require_once __SMARTY_DIR . "Smarty.class.php";

	$xmlp = new XMLPage();
	$pct = new PageContent();

	$dbObj=new xxDatabase(__CFG_HOSTNAME, __CFG_USERNAME, __CFG_PASSWORD, __CFG_DATABASE);
	$dbObj->open();
	$dbSet=new xxDataset($dbObj, __CFG_TAB_PREFIX, __CFG_TAB_PREFIX_ID);
	//$dbSet->open("SET SQL_BUFFER_RESULT = 1");
	//$dbSet->open("SET SQL_QUERY_CACHE_TYPE = ON");

	require_once __CFG_PATH_LIBS . "xx/class.ClientValidator.php";

	$ClientVLD = new ClientValidator($dbSet);
    $CONFIG = $ClientVLD->getConfigArray();

	/** Create session object */
	if(!isBlank($_GET['sessid']))
	{
	  $sID = new xxSession($CONFIG['sessionTime'], __CFG_SESSION_NAME, $_GET['sessid']);
	}
	else
	{
	  $sID = new xxSession($CONFIG['sessionTime'], __CFG_SESSION_NAME);
	}

	//$ClientVLD->checkBlackIP();

	define('__USER_REAL_IP', $_SERVER['HTTP_X_REAL_IP']);
    define('__USER_CURRENT_IP', $_SERVER['REMOTE_ADDR']);
    if(trim(__USER_REAL_IP))
    {
      define('__USER_IP', __USER_REAL_IP);
    }
    else
    {
  	  define('__USER_IP', __USER_CURRENT_IP);
    }

	/*include_once __CFG_PATH_LIBS."ip/geoip.inc";
  	$gi = geoip_open(__CFG_PATH_LIBS."ip/GeoIP.dat",GEOIP_STANDARD);
  	$GEOIP_COUNTRY_CODE = geoip_country_code_by_addr($gi, __USER_IP);
  	geoip_close($gi);*/

    define("__CFG_PATH_LANGUAGES_GENERATED", __CFG_PATH_LANGUAGES);
    define("__CFG_ADMIN_PANEL",false);

    require_once __CFG_PATH_LIBS . __CFG_PATH_CORE . "common.php";
	require_once __CFG_PATH_LIBS . __CFG_PATH_CORE . "languages.php";

    //$ClientVLD->filterBlockedCountries($GEOIP_COUNTRY_CODE);

	define('__LANG_CHARSET', $language['charset']);


	//$Timer->start("Smarty create");
	$tpl = new Smarty;
	$tpl->compile_check = ($CONFIG['SmartyCompileCheck'] == 'y') ? true : false;
	$tpl->template_dir = __CFG_PATH_TEMPLATE;
	$tpl->compile_dir = __CFG_PATH_COMPILE.$CONFIG['SiteTypeFolder'];
	$tpl->cache_dir = __CFG_PATH_CACHING;
	$tpl->plugins_dir = array(__CFG_PATH_SMPLUGINS, 'plugins');
	$tpl->left_delimiter = "{";
	$tpl->right_delimiter = "}";
	$tpl->default_modifiers = array('escape:"html"');
	$tpl->caching = $CONFIG['SmartyCaching'];
	$tpl->cache_lifetime = 0;
	//$tpl->use_sub_dirs = true;


	//$Timer->stop("Smarty create");

	set_time_limit (25);

	$tpl->assign("session", $sID->getSessionId());
	$tpl->assign("pathJS", __CFG_PATH_JAVASCRIPT);
	if (isset($SCRIPT_NAME)) {
		$tpl->assign("script_name", $SCRIPT_NAME);
	}
 	$tpl->assign("SID", $sID->getSessionID());
	$tpl->assign_by_ref("Config", $CONFIG);

	$tpl->assign_by_ref("SiteTitle", $CONFIG['SiteName']);
    $tpl->assign_by_ref("lang", $language);
    $tpl->assign_by_ref("ERRORS", $ERRORS);
    $tpl->assign_by_ref("MONTHS", $MONTHS);
    $tpl->assign_by_ref("langs", $langs);
    $CLIENT = array();
    $_FLAGS = array();
    $tpl->assign_by_ref("Client", $CLIENT);
    $tpl->assign_by_ref("FLAGS", $_FLAGS);
    $tpl->assign("curr_link", $curr_link);

    $tpl->assign('TRUE', __TRUE);
	$tpl->assign('FALSE', __FALSE);
	$tpl->assign('ERROR', __ERROR);

	$LangVarsArr = array('title', 'description', 'body');
	foreach($LangVarsArr as $n => $varname)
	{
      $tpl->assign('F'.$varname, $varname.__FLANG);
 	}

    $SubMenu = array();
    $tpl->assign_by_ref('SubMenu', $SubMenu);

    $tpl->assign("LANG", __LANG);
    $tpl->assign("SITEPATH", getPath());

    $HOST = $CONFIG['SiteProtocol']."://".$CONFIG['SiteDomain'];
    $BaseURL = $HOST.getPath();
    $HOST .= "/";
    $tpl->assign_by_ref('BaseURL', $BaseURL);
    $tpl->assign('HOST', $HOST);

    $ServerBaseURL = $CONFIG['ServerProtocol']."://".$CONFIG['ServerDomain']."/";
    $tpl->assign_by_ref('ServerBaseURL', $ServerBaseURL);


    $Timer->stop("loader");
    //$Timer->display();

?>